<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: 32104
  Date: 2024/6/21
  Time: 下午2:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>处理修改</title>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    String name = request.getParameter("name");
    Integer age = Integer.parseInt(request.getParameter("age"));
    String address = request.getParameter("address");
    String phone = request.getParameter("phone");
    Integer sex = Integer.parseInt(request.getParameter("sex"));
    try {

        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/student?serverTimezone=Asia/Shanghai";
        String userName = "root";
        String userPassword = "root";
        Connection connection = DriverManager.getConnection(url, userName, userPassword);
        String sql = "update user_info set name=?, age=?, address=?, phone=?,sex=? where name=?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, name);
        preparedStatement.setInt(2, age);
        preparedStatement.setString(3, address);
        preparedStatement.setString(4, phone);
        preparedStatement.setInt(5,sex);
        preparedStatement.setString(6, name);
        int i = preparedStatement.executeUpdate();
        if (i > 0) {
%>
<script type="text/javascript">
    alert("修改成功")
    window.location.href = "../select/select01.jsp"
</script>
<%
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
</body>
</html>
